﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:conv="clr-namespace:DaxStudio.UI.Converters">

    <conv:OffsetConverter x:Key="OffsetConverter"/>

    <BitmapImage x:Key="SpinnerMask"  UriSource="..\images\spinnermask.png" />

    <Storyboard x:Key="Rotation">
        <DoubleAnimation Storyboard.TargetName="rotateTransform"
                       Storyboard.TargetProperty="Angle"
                       From="0" To="360" Duration="00:00:01"
                       RepeatBehavior="Forever"/>
    </Storyboard>

    <Style x:Key="LabelSpinnerStyle" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Padding" Value="0"/>
        <!--<Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Label}">

                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                        <StackPanel Orientation="Horizontal">
                            <Grid Name="LayoutRoot" RenderTransformOrigin="0.5,0.5" 
                                  Width="{TemplateBinding Height,Converter={StaticResource OffsetConverter},ConverterParameter=3}"
                                  Height="{TemplateBinding Height,Converter={StaticResource OffsetConverter},ConverterParameter=3}"
                                  Background="{TemplateBinding Background}">

                                <Grid.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform x:Name="rotateTransform"/>
                                    </TransformGroup>
                                </Grid.RenderTransform>
                                <Ellipse Margin="2" Fill="{TemplateBinding Foreground }">


                                    <Ellipse.OpacityMask>
                                        <ImageBrush ImageSource="../images/spinnermask.png" Stretch="None"/>
                                    </Ellipse.OpacityMask>
                                </Ellipse>
                                <Grid.OpacityMask>
                                    <RadialGradientBrush>
                                        <GradientStop Color="Black" Offset="0.96"/>
                                        <GradientStop Color="Transparent" Offset="0.5"/>
                                    </RadialGradientBrush>
                                </Grid.OpacityMask>
                                <Grid.Triggers>
                                    <EventTrigger RoutedEvent="Window.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="rotateTransform"
                                            Storyboard.TargetProperty="Angle"
                                            From="0" To="360" Duration="00:00:01"
                                            RepeatBehavior="Forever"/>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Grid.Triggers>
                            </Grid>
                            <ContentPresenter Margin="5,0,0,0" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </StackPanel>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>